package cn.com.demo.microservice.anquan.mapper;

import cn.com.demo.microservice.entity.AqUser;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface AqUserMapper {
    @Delete({
        "delete from aq_user",
        "where ur_id = #{urId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer urId);

    @Insert({
        "insert into aq_user (ur_id, ur_name, ",
        "ur_phone, ur_sex, ur_avatar, ",
        "ur_introduction)",
        "values (#{urId,jdbcType=INTEGER}, #{urName,jdbcType=VARCHAR}, ",
        "#{urPhone,jdbcType=VARCHAR}, #{urSex,jdbcType=CHAR}, #{urAvatar,jdbcType=VARCHAR}, ",
        "#{urIntroduction,jdbcType=VARCHAR})"
    })
    @Options(useGeneratedKeys = true, keyColumn = "ur_id", keyProperty = "urId")
    int insert(AqUser record);

    @InsertProvider(type=AqUserSqlProvider.class, method="insertSelective")
    int insertSelective(AqUser record);

    @Select({
        "select",
        "ur_id, ur_name, ur_phone, ur_sex, ur_avatar, ur_introduction",
        "from aq_user",
        "where ur_id = #{urId,jdbcType=INTEGER}"
    })
    @Results(id="UserMapper",value={
        @Result(column="ur_id", property="urId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="ur_name", property="urName", jdbcType=JdbcType.VARCHAR),
        @Result(column="ur_phone", property="urPhone", jdbcType=JdbcType.VARCHAR),
        @Result(column="ur_sex", property="urSex", jdbcType=JdbcType.CHAR),
        @Result(column="ur_avatar", property="urAvatar", jdbcType=JdbcType.VARCHAR),
        @Result(column="ur_introduction", property="urIntroduction", jdbcType=JdbcType.VARCHAR)
    })
    AqUser selectByPrimaryKey(Integer urId);

    @UpdateProvider(type=AqUserSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(AqUser record);

    @Update({
        "update aq_user",
        "set ur_name = #{urName,jdbcType=VARCHAR},",
          "ur_phone = #{urPhone,jdbcType=VARCHAR},",
          "ur_sex = #{urSex,jdbcType=CHAR},",
          "ur_avatar = #{urAvatar,jdbcType=VARCHAR},",
          "ur_introduction = #{urIntroduction,jdbcType=VARCHAR}",
        "where ur_id = #{urId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(AqUser record);

    @ResultMap("UserMapper")
    @Select("select ur.* from aq_user ur, aq_account acc where acc.acc_code=#{accCode} and acc.acc_ur_id=ur.ur_id")
    AqUser selectByAccount(String accCode);

    @ResultMap("UserMapper")
    @Select("select * from aq_user")
    List<AqUser> selectAll();

}